package com.qf.hsr.factorybean;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.beans.factory.FactoryBean;


/**
 * @author q
 * @version V1.0
 * @date 2021/11/08
 **/
public class MySqlSessionFactoryBean implements FactoryBean<SqlSessionFactory> {
    /**
     * 用来创建getObjectType方法返回的类型的对象
     * @return
     * @throws Exception
     */
    @Override
    public SqlSessionFactory getObject() throws Exception {
        return new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("mybatis-config.xml"));
    }

    /**
     * 指定当前FactoryBean创建的对象的具体类型
     * @return
     */
    @Override
    public Class<?> getObjectType() {
        return SqlSessionFactory.class;
    }

    /**
     * 是否单例
     * @return
     */
    @Override
    public boolean isSingleton() {
        return true;
    }
}
